package com.sanrenzu.everybodytv.ui.recommenditent;

import android.os.Handler;

import com.sanrenzu.everybodytv.bean.sms.IntentBean;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by asus on 2016/9/7.
 */
public class RecommendIntentPresenter implements RecommendIntentContract.Presenter {

    private RecommendIntentContract.View view;
    private RecommendIntentContract.Model model;
    private Handler handler = new Handler();
    private IntentBean body;

    public RecommendIntentPresenter(RecommendIntentContract.View view){
        this.view = view;
        model = new RecommendIntentModel();
    }

    @Override
    public void getRecommendIntent(String name) {
        model.getRecommendIntent(name, new Callback<IntentBean>() {
            @Override
            public void onResponse(Call<IntentBean> call, Response<IntentBean> response) {
                body = response.body();
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.onGetRecommendSuccess(body);
                    }
                });
            }

            @Override
            public void onFailure(Call<IntentBean> call, Throwable t) {
                t.printStackTrace();
            }
        });
    }
}
